<?php
/**
 * Created by PhpStorm.
 * User: woody
 * Date: 17-2-16
 * Time: 下午10:46
 */

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Admin\AdminController;
use Illuminate\Http\Request;

use App\Models\StoreOrders;

class OrderController extends AdminController {

    private $_length;

    public function __construct()
    {
        parent::__construct();
        $this->_length = 20;
        $this->_response['_active']['_model'] = 'order';
    }


    public function getList(Request $request){
        $page = 1;
        if($request->has('page')){
            $page = $request->get('page');
        }

        $search = [
            'status'    => [2,3,4,5]
        ];

        $offset = ($page -1) * $this->_length;

        $storeOrdersModel = new StoreOrders();

        $order = $storeOrdersModel->getOrderInfo($search , $offset , $this->_length);

        $status = \Config::get('order.status');

        foreach ($order['list'] as $o){
            $o->status_msg = $status[$o->status];
        }

        $this->_response['order'] = $order;
        $this->_response['search'] = $search;
        $this->_response['order']['pageData']['page'] = $page;
        $this->_response['order']['pageData']['pageHtml'] = self::getPageHtml($page , $this->_response['order']['pageData']['lastPage'] , '/admin/order?');
        return view('admin.order.list' , $this->_response);
    }

}